<template>
  <div class="mainlist mainwarp">
    <div class="searchFormBox">
      <el-form :inline="true" ref="searchCol" :model="searchCol" label-width="80px" label-suffix=":" style="text-align: left;">
        <el-form-item label="角色名称" prop="name">
          <el-input v-model="searchCol.name" placeholder="输入角色名称" clearable></el-input>
        </el-form-item>
        <el-form-item class="seachButton">
          <el-button type="primary" @click="getRoleList">搜索</el-button>
        </el-form-item>

        <el-form-item style="margin-right: 0; float: right">
          <el-button type="success" @click="doAddRole">添加角色</el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-table stripe :data="roleData" border :height="height + 'px'">
      <el-table-column label="序号" type="index" width="50" align="center"></el-table-column>
      <el-table-column label="名称" prop="name" min-width="200">
        <template slot-scope="scope">
          <span v-if="scope.row.name !== '系统管理员'">{{ scope.row.name }}</span>
          <span v-else><span style="font-weight:bold;">{{ scope.row.name }}</span>（不能编辑或删除）</span>
        </template>
      </el-table-column>
      <el-table-column label="创建者" prop="createByName" min-width="100" align="center"></el-table-column>
      <el-table-column label="创建时间" prop="createTime" min-width="110" align="center"></el-table-column>
      <el-table-column label="更新者" prop="updateByName" min-width="100" align="center"></el-table-column>
      <el-table-column label="更新时间" prop="updateTime" min-width="110" align="center"></el-table-column>
      <el-table-column label="状态" prop="status" min-width="80" align="center">
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.status === 0">已禁用</el-tag>
          <el-tag v-else-if="scope.row.status === 1">可用</el-tag>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" min-width="120" align="center">
        <template slot-scope="scope">
          <el-button @click="doDetail(scope.row)" type="text" size="small">查看权限</el-button>
          <el-button @click="doEdit(scope.row)" type="text" size="small" v-if="scope.row.name !== '系统管理员'">编辑</el-button>
          <el-button @click="setStatus(scope.row, 1)" v-if="scope.row.status === 0 && scope.row.name !== '系统管理员'" type="text" size="small">恢复</el-button>
          <el-button @click="setStatus(scope.row, 0)" v-else-if="scope.row.status == 1 && scope.row.name !== '系统管理员'" type="text" size="small">禁用</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="searchCol.page"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="searchCol.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    ></el-pagination>

    <el-dialog :lock-scroll="false" :title="dialogTitle" :visible.sync="dialogFlag" width="35%" :close-on-click-modal="false" @close="closeDialog" v-if="dialogFlag">
      <el-form ref="roleForm" :model="roleForm" label-width="130px" label-suffix=":">
        <el-form-item label="名称" prop="name">
          <el-input v-model="roleForm.name" placeholder="请输入角色名称" :disabled="isDisable" />
        </el-form-item>
        <el-form-item label="权限" prop="description">
          <el-tree
            ref="menuTree"
            :disabled="isDisable"
            :check-on-click-node="true"
            :props="props"
            :data="menus"
            node-key="shiroKey"
            show-checkbox
            :check-strictly="true"
            :default-checked-keys="defaultCheckedKeys"
            @check-change="menuCheckChange">
          </el-tree>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer" v-if="!isDisable">
        <el-button type="primary" @click="submitAddRole">提交</el-button>&nbsp;&nbsp;
        <el-button @click="closeDialog()">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script lang="js" src="./RoleList.js"></script>
<style scoped>
.warning {
  color: red;
  margin-bottom: 10px;
  margin-top: -10px;
}
</style>